<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="taglibs.jsp" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
	
  <link rel="stylesheet" href="${ctx}/css/common.css" type="text/css"></link>
  <link rel="stylesheet" href="${ctx}/css/reset.css" type="text/css"></link>
  <script type='text/javascript' src='${ctx}/dwr/interface/UserDwrManager.js'></script>
  <script type='text/javascript' src='${ctx}/dwr/engine.js'></script>
  <script type='text/javascript' src='${ctx}/dwr/util.js'></script>
  <script type="text/javascript" src="${ctx}/js/System/UserManager.js"></script>
  <script type="text/javascript" src="${ctx}/js/jquery-1.7.2.js"></script>
  <script type="text/javascript" src="${ctx}/js/jquery.easydrag.handler.beta2.js"></script>
  <script language="javascript">

</script>
  </head>
  
  <body>
  	  <div class="head">
  		<div class="curloc"><span>当前位置:系统管理>>用户管理</span></div>
  	  </div>
	  <div class="query">
	  <form action="" method="post" id="query_form">
	  <div class="querytype">
	  	<label>查询条件：</label>
	  	<select class="queryselect" id="query_select">
	  		<option value="userall">
	  		全部
	  		</option>
			<option value="username">
			用户名
			</option >
			<option value="userrole">
			角色
			</option>
			<option value="userpower">
			权限
			</option>
			<option value="userstatus">
			状态
			</option>
		</select>
		<input type="text" id="userqueryinfo" name="userqueryinfo"/>
		</div>
	  	<div class="querybtn">
	  		<span class="STYLE1" style="margin-left: 10px"><img src="${ctx}/images/a1.gif" width="9" height="9" /></span>
            <span class="STYLE1"> </span><a style="cursor: pointer;text-decoration: none;color: black;" href="javaScript:queryhref()">查询</a><span class="STYLE1"></span>
	  	</div>
	  	<div style="float: right; padding-right: 20px">
	  			<span class="STYLE1"><img src="${ctx}/images/001.gif" width="9" height="9" /></span>
            	<span class="STYLE1"> </span><a href="javaScript:popupDiv('pop_add_div')">新增</a><span class="STYLE1"></span>
	  	</div>
	  <div class="clear"></div>
	  </form>
	  </div>
        <div id="main">
        <table id="detail_t">
          <tr>
        	<th>序号</th>
            <th>用户名</th>
            <th>角色</th>
            <th>状态</th>
            <th>权限</th>
            <th>更多操作</th>
          </tr>
          <c:forEach items="${page.list}" var="list" varStatus="status">
         <tr class="items">
         	<td>${status.index+1}</td>
    		<td>${list.username}</td>
    		<td>${list.role.name}</td>
    		<td>${list.status==true?"可用":"不可用"}</td>
    		<td>${list.power.name}</td>
    		<td height="18" bgcolor="#FFFFFF">
    		<div align="center">
    		<span class="STYLE1"><img src="${ctx}/images/037.gif" width="9" height="9" /></span>
            <span class="STYLE1"> [</span><a href="javaScript:passwordhref('${list.username}')">修改密码</a><span class="STYLE1">]</span>
            &nbsp;&nbsp;&nbsp;
            <span class="STYLE1"><img src="${ctx}/images/037.gif" width="9" height="9" /></span>
            <span class="STYLE1"> [</span><a href="javaScript:updatehref('${list.username}','${list.role.id}','${list.power.id}','${list.status==true?"1":"2"}')">编辑</a><span class="STYLE1">]</span>
            &nbsp;&nbsp;&nbsp;
            <span class="STYLE2"><img src="${ctx}/images/010.gif" width="9" height="9" /></span>
            <span class="STYLE2"> </span><span class="STYLE1">[</span><a href="javascript:void(0)" onclick="Delete('${list.username}')">删除</a><span class="STYLE1">]</span>
            </div>
    	   </td>
        </tr>
    </c:forEach>
      </table>
			<div class="manu">共${page.totalCount}条记录当前第<font color="#ff6600">${page.pageNo}/${page.pageCount}</font>页
				 <a href="UserManagerServlet?pageNo=${1}">首页</a>
				  <a href="UserManagerServlet?pageNo=${page.pageNo-1}">上一页</a>
				  <a href="UserManagerServlet?pageNo=${page.pageNo+1}">下一页</a>
				  <a href="UserManagerServlet?pageNo=${page.pageCount}">末页</a> 每页显示
				  <input type="text" name="pageSize"  id="pageSize" size="4"/>条
				  <input type="button" value="提交" class="submitbuttton" onclick="changePageSize()"/> 
			</div>
		</div>
		
		<div id="pop_update_div" class="pop_box">
			<div class="p_head">
				<span class="p_h_title">用户信息修改</span> <span><a
					class="p_h_close" onclick="hideDiv('pop_update_div');" title="close">X</a>
				</span>
			</div>
			<div class="p_box_body" id="p_b_body">
				<div class="p_con">
					<table id="p_con_t">
					  <tr>
					    <td class="t1">用户名：</td>
					    <td><input type="text" value="1" id="update_name" readonly="readonly"/></td>
					  </tr>
					  
					  <tr>
					    <td class="t1">角色：</td>
					    <td> <select id="update_role">
					    </select></td>
					  </tr>
					  <tr>
					  <tr>
					    <td class="t1">权限：</td>
					    <td> <select id="update_power">
					    <option value="1">读写</option>
					    <option value="2">只读</option>
					    </select></td>
					  </tr>
					    <td class="t1">状态：</td>
					    <td>
					    <select id="update_status">
					    <option value="1">可用</option>
					    <option value="2">不可用</option>
					    </select>
					    </td>
					  </tr>
					  <tr>
					  	<td></td>
					  	<td><input type="button" value="修改" onclick="fuserupdatebtn()"/></td>
					  </tr>
					</table>
				</div>
			</div>
		</div>
		<div id="pop_add_div" class="pop_box">
			<div class="p_head">
				<span class="p_h_title">添加用户</span> <span><a
					class="p_h_close" onclick="hideDiv('pop_add_div');" title="close">X</a>
				</span>
			</div>
			<div class="p_box_body" id="p_b_body">
				<div class="p_con">
					<table id="p_con_t">
					  <tr>
					    <td class="t1">用户名：</td>
					    <td><input type="text" id="user_add_name"/></td>
					  </tr>
					  <tr>
					    <td class="t1">密码：</td>
					    <td><input type="password" id="user_add_password1"/></td>
					  </tr>
					  <tr>
					    <td class="t1">确认密码：</td>
					    <td><input type="password" id="user_add_password2"/></td>
					  </tr>
					  <tr>
					    <td class="t1">角色：</td>
					    <td> <select id="user_add_role">
					    <option value="1">超级管理员</option>
					    <option value="2">人员档案管理员</option>
					    <option value="3">人事调配管理员</option>
					    <option value="4">培训管理员</option>
					    </select></td>
					  </tr>
					  <tr>
					    <td class="t1">权限：</td>
					    <td> <select id="user_add_power">
					    <option value="1">读写</option>
					    <option value="2">只读</option>
					    </select></td>
					  </tr>
					  <tr>
					    <td class="t1">状态：</td>
					    <td>
					    <select id="user_add_status">
					    <option value="1">可用</option>
					    <option value="2">不可用</option>
					    </select>
					    </td>
					  </tr>
					  <tr>
					  	<td></td>
					  	<td><input type="button" value="添加" onclick="fusernewbtn()"/></td>
					  </tr>
					</table>
				</div>
			</div>
		</div>
		<div id="pop_update_password_div" class="pop_box">
			<div class="p_head">
				<span class="p_h_title">修改用户密码</span> <span><a
					class="p_h_close" onclick="hideDiv('pop_update_password_div');" title="close">X</a>
				</span>
			</div>
			<div class="p_box_body" id="p_b_body">
				<div class="p_con">
					<table id="p_con_t">
					  <tr>
					    <td class="t1">用户名：</td>
					    <td><input type="text" readonly="readonly" id="update_password_username"/></td>
					  </tr>
					  <tr>
					    <td class="t1">密码：</td>
					    <td><input type="password" id="update_password1"/></td>
					  </tr>
					  <tr>
					    <td class="t1">确认密码：</td>
					    <td><input type="password" id="update_password2"/></td>
					  </tr>
					  	<td></td>
					  	<td><input type="button" value="修改" onclick="fupdatepassword()"/></td>
					  </tr>
					</table>
				</div>
			</div>
		</div>
</body>
<script type="text/javascript">
function hideDiv(div_id){
            $("#" + div_id).animate({opacity: "hide" }, 300);
}
function popupDiv(div_id) {
            var div_obj = $("#" + div_id);
            //窗口宽度,高度
            var winWidth = $(window).width();
            var winHeight = $(window).height();
            //弹出的div的宽度,高度
            var popHeight = div_obj.height();
            var popWidth = div_obj.width();
            div_obj.animate({
				 opacity: "show", left: (winWidth-popWidth) / 2, top: (winHeight-popHeight)/2,width:popWidth,height:popHeight}, 300);          
}

function queryhref(){
	var queryuser_index=document.getElementById("query_select").selectedIndex;
	var userquerytype=document.getElementById("query_select").options[queryuser_index].value;
	var userqueryinfo=document.getElementById("userqueryinfo").value;
	if("userall"==userquerytype){
		document.getElementById("query_form").action="UserManagerServlet?userquerytype="+userquerytype;
		document.getElementById("query_form").submit();
	}else{
		if(""!=userqueryinfo){
			document.getElementById("query_form").action="UserManagerServlet?userquerytype="+userquerytype;
			document.getElementById("query_form").submit();
		}else{
			alert("请输入查询信息");
			return;
		}
	}
}

function updatehref(user_name,user_roleid,user_powerid,user_statusid){
	var update_role=document.getElementById("update_role");
	UserDwrManager.getAllRole(function(data) {
		DWRUtil.removeAllOptions(update_role);
		DWRUtil.addOptions(update_role,data,'id','name');
		doInitSelection(update_role,user_roleid);
	});
	//$("#update_dept_header").val(header_id);
	document.getElementById("update_name").value=user_name;
	var update_power_obj=document.getElementById("update_power");
	var update_status_obj=document.getElementById("update_status");
	doInitSelection(update_power_obj,user_powerid);
	doInitSelection(update_status_obj,user_statusid);
	popupDiv('pop_update_div');
}

function passwordhref(username){
	document.getElementById("update_password_username").value=username;
	popupDiv('pop_update_password_div');
}

function Delete(id) {
  if (confirm("你确认删除这条记录吗?")) {
     fuserdeletebtn(id);
  }
}
$(function() {
            $(".pop_box").easydrag();
            $(".pop_box").setHandler(".pop_box .p_head");
});
</script>
</html>